package com.hm.shopping.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hm.common.su.bean.PageInfo;
import com.hm.common.su.bean.PageInfo.PageInfoParam;
import com.hm.common.su.bean.ServerResponse;
import com.hm.shopping.auto.su.ControllerResult;
import com.hm.shopping.auto.su.R.Restful;
import com.hm.shopping.auto.su.helper.HmSessionFactory;
import com.hm.shopping.def.OrderStateEnum;
import com.hm.shopping.service.OrderService;
import com.hm.shopping.vo.OrderLogisticsVo;
import com.hm.shopping.vo.su.BuyGoodsSnapshotVo.GoodsIntroductionSnapshotVo;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * @author shishun.wang
 * @date 2018年2月24日 下午3:47:32
 * @version 1.0
 * @describe 订单信息管理
 */
@Slf4j
@ResponseBody
@RestController
@RequestMapping(Restful.API + "/order")
public class OrderApi {

	@Autowired
	private OrderService orderService;
	
	private static final String SWWAGER_TAG = "订单信息管理";
	
	@RequestMapping(value = "/{pageNumber}/{pageSize}", method = RequestMethod.GET)
	@ApiOperation(tags = SWWAGER_TAG, value = "查询分页订单信息", httpMethod = "GET", notes = "com.hm.shopping.api.OrderApi::queryBuyerGoodsSnapshots")
	public ResponseEntity<ServerResponse<PageInfo<GoodsIntroductionSnapshotVo>>> queryBuyerGoodsSnapshots(
			@ApiParam(required = true, name = "pageNumber", value = "分页号(第一页值为1,最小页码不能小于1)") @PathVariable("pageNumber") int pageNumber,
			@ApiParam(required = true, name = "pageSize", value = "分页大小") @PathVariable("pageSize") int pageSize,
			@ApiParam(required = false, name = "orderPayState", value = "订单状态") @RequestParam(required = false, name = "orderPayState") OrderStateEnum orderPayState){
		log.debug("用户{},查询分页订单信息记录", HmSessionFactory.currentUserId());
		return ControllerResult.success(orderService.queryBuyerGoodsSnapshots(new PageInfoParam(pageNumber, pageSize), HmSessionFactory.currentUserIdString(), orderPayState));
	}
	
	@RequestMapping(value = "/fcourier", method = RequestMethod.PATCH)
	@ApiOperation(tags = SWWAGER_TAG, value = "商品订单发货", httpMethod = "PATCH", notes = "com.hm.shopping.api.OrderApi::finishOrderCourier")
	public ResponseEntity<ServerResponse<Boolean>> finishOrderCourier(
			@ApiParam(required = true, name = "body") @RequestBody(required = true) OrderLogisticsVo orderLogistics){
		orderService.finishOrderCourier(orderLogistics);
		return ControllerResult.success(true);
	}
}
